package www.truongnha.com;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.Toast;

public class SubmitMarkOld extends Activity {
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.submit_mark);
		
		//Virtual data:
		String subject = "Hóa Học";
		String className = "12C12";
		setTitle("Nhập điểm môn "+ subject+" Lớp "+ className);
		TableLayout aTable=(TableLayout) findViewById(R.id.mark);
		
		String[][] marks =new String[30][17];
		for(int i = 0; i< 30; i++){
			for(int j = 0; j< 17; j++ ){
				marks[i][j] = i*j+1 +"";
			}//end for.
		}//End for
		appendRows(aTable, marks);
	}//End onCreate

	private void appendRows(TableLayout table, String[][] amortization) {
		int rowSize=amortization.length;
		int colSize=(amortization.length>0)?amortization[0].length:0;
		for(int i=0; i<rowSize; i++){
			TableRow row = new TableRow(this);
			TableLayout.LayoutParams tableRowParams =
					  new TableLayout.LayoutParams
					  (TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
			tableRowParams.setMargins(1, 1, 1, 1);

			row.setLayoutParams(tableRowParams);
			row.setBackgroundColor(Color.RED);
			
			for(int j=0; j<colSize; j++){
				final EditText c = new EditText(this);
				//TextView c = new TextView(this);
				c.setBackgroundColor(Color.WHITE);
				
				c.setLines(1);
				//c.setFocusable(false);
				//c.setFocusableInTouchMode(false);
				if( j == 0 ){
					c.setText(i+"");
				} else{
					if( j == 1){
						if( i%2 == 0){
							c.setText("Nguyen Xuan Thanh");
							c.setOnClickListener(new View.OnClickListener() {
								
								public void onClick(View v) {
									// TODO Auto-generated method stub
									Toast.makeText(getApplicationContext(), "Click", Toast.LENGTH_SHORT).show();
								}
							});
						}else{
							c.setText("Nguyen A");
							c.setOnFocusChangeListener( new View.OnFocusChangeListener() {
								
								public void onFocusChange(View v, boolean hasFocus) {
									// TODO Auto-generated method stub
									Toast.makeText(getApplicationContext(), "OnfocusChangeListenner \n "+ c.getText().toString(), Toast.LENGTH_SHORT).show();
								}
							});
						}
					}
					else 
						c.setText("9");
				}//End.
				
				c.setPadding(5, 5, 5, 5);
				row.addView(c);
			}//End for.
			table.addView(row, new TableLayout.LayoutParams());
			
		}//End for.
	}//End appendRows
}//End class
